/**
 * Copyright (c) 2015—2017 Zerone.Co.Ltd. All rights reserved.
 */
package com.zerone.pay.merchant.executor;

import org.springframework.beans.factory.annotation.Autowired;

import com.acooly.core.common.facade.SingleResult;
import com.acooly.core.utils.mapper.BeanCopier;
import com.acooly.module.adk.executor.InvokeServiceAdapter;
import com.acooly.module.adk.executor.ServiceContext;
import com.acooly.module.adk.executor.annotation.Invoke;
import com.zerone.facade.merchant.info.MerchantInfo;
import com.zerone.facade.merchant.order.MerchantQueryOrder;
import com.zerone.pay.merchant.repository.dao.MerchantDao;
import com.zerone.pay.merchant.repository.entity.MerchantEntity;
import com.zerone.payment.common.exception.PaymentException;

/**
 *
 * @author glassescat <a href="">零一零一科技</a>
 */
@Invoke(serviceName = "queryByMerchantId",logName = "merchant")
public class MerchantInfoQueryInvoke extends InvokeServiceAdapter<MerchantQueryOrder,SingleResult<MerchantInfo>> {

    @Autowired
    private MerchantDao merchantDao;

    @Override
    public void invoke(ServiceContext<MerchantQueryOrder, SingleResult<MerchantInfo>> serviceContext) {
        MerchantEntity entity = merchantDao.findByMerchantId(serviceContext.getParameter().getMerchantId());
        if (entity == null ){
            throw new PaymentException("商户信息不存在");
        }
        MerchantInfo merchantInfo = new MerchantInfo();
        BeanCopier.copy(entity,merchantInfo);
        serviceContext.result().setDto(merchantInfo);
    }
}
